// packageA/member/Organization/Organization.js
Page({
  data: {
    list: [],
    jingli: {},
    goodsId: '3040',
    apiUrl: 'https://shops.cg500.com/',
    // avatar: 'https://shops.cg500.com/static/images/photo-mr.jpg',
    // avatar1: '/static/images/photo-mr.jpg',
    avatar: '',
    goodsList: [],
    currentTab: -1,
    navBarHeight: 0, // 导航栏高度
    menuRight: 0, // 胶囊距右方间距（方保持左、右间距一致）
    menuTop: 0, // 胶囊距底部间距（保持底部间距一致）
    menuHeight: 0, // 胶囊高度（自定义内容可与胶囊高度保证一致）
  },
  onLoad(){
    this.getList()
    const that = this;
    // 获取系统信息
    const systemInfo = wx.getSystemInfoSync();
    // 胶囊按钮位置信息
    const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
    // 导航栏高度 = 状态栏高度 + 44
    let navBarHeight = systemInfo.statusBarHeight + 44;
    let menuRight = systemInfo.screenWidth - menuButtonInfo.right;
    let menuTop=  menuButtonInfo.top;
    let menuHeight = menuButtonInfo.height;
    that.setData({
      navBarHeight: navBarHeight,
      menuRight: menuRight,
      menuTop: menuTop,
      menuHeight: menuHeight
    })
    
    console.log(that.data.navBarHeight,that.data.menuRight,that.data.menuTop,that.data.menuHeight,'\\\\\\\\\\\\')
    // const aaa =  this.startsWithHttp(this.data.avatar)
    // const bbb =  this.startsWithHttp(this.data.avatar1)
    // console.log(aaa,bbb,'22222222222222')
  },
  onLaunch: function(options) {
   
},
  fanhui(){
    // wx.navigateBack({
    //   delta: 1
    // })
    wx.reLaunch({
      url: '/packageG/pages/member/extension/extension',
    })
  },
  getList(){
    let _this = this
    console.log(_this.data.goodsId,'goodsId')
    wx.request({
      url: 'https://shops.cg500.com/addons/yun_shop/api.php?i=31&type=2&route=Gongxiao.jiagou', // 接口的URL地址
      method: 'POST', // 请求方法，可以是GET、POST等
      data: {
        // 需要发送给接口的数据，根据接口要求进行定义
        uid: wx.getStorageSync('uid'),
        // uid: '20205',
        goods_id: _this.data.goodsId,
        // goods_id: '3040',
      },
      success(res) {
        // 接口请求成功的回调函数
        console.log(res.data.data.list); // 打印接口返回的数据
        _this.setData({
          list: res.data.data.list,
          jingli: res.data.data.jl,
          goodsList: res.data.data.goods,
          goodsId: res.data.data.goods_id,
          currentTab: res.data.data.goods_id
        });
       
        //  判断头像是否以http开头
        let isHasHttp = _this.startsWithHttp(res.data.data.jl.avatar)
        console.log(isHasHttp,'isHasHttpisHasHttp')
        if(isHasHttp) {
          _this.setData({
          avatar: res.data.data.jl.avatar
        });
        }else {
          _this.setData({
          avatar: apiUrl + res.data.data.jl.avatar
        });
        }
      },
      fail(res) {
        // 接口请求失败的回调函数
        console.error(res.errMsg); // 打印错误信息
      },
    });
  },
  startsWithHttp(str) {
    console.log(str,'str')
    const regex = /^http/;
    return regex.test(str);
  },
  changeStatus(e){
    console.log(e.currentTarget.dataset.item,'changeStatus')
    let goodsId = e.currentTarget.dataset.item.id
    // let index = e.currentTarget.dataset.index
    let index = e.currentTarget.dataset.index
    this.setData({
      goodsId: goodsId,
      currentTab: goodsId
    })
    this.getList()
  },
  toggleItem(e) {
    console.log(e, 'eee')
    const index = e.currentTarget.dataset.index;
    const item = this.data.list[index];
    item.active = !item.active;
    this.setData({
      list: this.data.list
    });
  },
  toggleItem1(e) {
    console.log(e, '1111')
    const index = e.currentTarget.dataset.index;
    const indexs = e.currentTarget.dataset.indexs;
    const item = this.data.list[index].list[indexs];
    console.log(item,'item')
    item.active = !item.active;
    this.setData({
      list: this.data.list
    });
  },
  onShareAppMessage() {
    return {};
  },
})